<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <LINK rel="Bookmark" href="yi.ico" >
    <LINK rel="Shortcut Icon" href="yi.ico" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="libs/html5.js"></script>
    <script type="text/javascript" src="libs/respond.min.js"></script>
    <script type="text/javascript" src="libs/PIE_IE678.js"></script>
    <![endif]-->
    <link href="libs/h-ui/css/H-ui.min.css" rel="stylesheet" type="text/css" />
    <link href="libs/h-ui.admin/css/H-ui.login.css" rel="stylesheet" type="text/css" />
    <link href="libs/Hui-iconfont/1.0.7/iconfont.css" rel="stylesheet" type="text/css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>登录 - 接口自动化测试平台</title>
    </head>
<body>
<input type="hidden" id="TenantId" name="TenantId" value="" />
<div class="header"></div>
<div class="loginWraper">
    <div id="loginform" class="loginBox">
        <form class="form form-horizontal" action="index.html" method="post">
            <div class="row cl">
                <label class="form-label col-xs-3"><i class="Hui-iconfont">&#xe60d;</i></label>
                <div class="formControls col-xs-8">
                    <input id="username"  type="text" placeholder="账户" class="input-text size-L">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-3"><i class="Hui-iconfont">&#xe60e;</i></label>
                <div class="formControls col-xs-8">
                    <input id="password"  type="password" placeholder="密码" class="input-text size-L">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-3"><i class="Hui-iconfont">&#xe613;</i></label>
                    <div class="formControls col-xs-8">             
	                    <input id="verifyCode"  type="text" placeholder="验证码" class="input-text size-L" style="width:280px;">                 
	                    <img src="" style="width:80px;height:40px;cursor:pointer;"/>
                	</div>
            </div>
            <div class="row cl">
                <div class="formControls col-xs-8 col-xs-offset-3">
                    <label for="online">
                        <input type="checkbox" name="online" id="online" checked="checked">使我保持登录状态</label>
                </div>
            </div>        
            <div class="row cl">
                <div class="formControls col-xs-8 col-xs-offset-3">
                    <input id="loginBtn" type="button" class="btn btn-success radius size-L" value="&nbsp;登&nbsp;&nbsp;&nbsp;&nbsp;录&nbsp;">
                    <input name="" type="reset" class="btn btn-default radius size-L" value="&nbsp;取&nbsp;&nbsp;&nbsp;&nbsp;消&nbsp;">
                    <p id="loginTip" style="color: red;"></p>
                </div>
            </div>
        </form>
    </div>
</div>
<div class="footer">Copyright By DevopsGroup@2017-2020 </div>
<script type="text/javascript" src="libs/jquery/1.9.1/jquery.js"></script>
<script type="text/javascript" src="libs/h-ui/js/H-ui.js"></script>
<script type="text/javascript" src="libs/layer/2.1/layer.js"></script>
<script type="text/javascript" src="js/globalConstant.js"></script>
<script type="text/javascript" src="js/ajaxErrorHandler.js"></script>
<script>
    $(document).ready(function(){
    	 $("#verifyCode").siblings('img').click(function(){
    		 var that = this;
    		 $.get(REQUEST_URL.LOGIN.CREATE_VERIFY_CODE, function(data){
        		 if (data.returnCode == 0) {
        			 $(that).attr('src', 'data:image/png;base64,' + data.data);
        		 }
        	 });
    	 });
    	 
    	 $("#verifyCode").siblings('img').click();
    	 
    	 $("#loginBtn").click(userLogin);
    	 //监听键盘回车事件
    	 $(document).keyup(function (event) {
    		 var keycode = event.which;
    		 if(keycode==13){
    			 $("#loginBtn").click(); 
    		 }
    		 
    	 });

        //判断当前是否有用户登录
        $.post(REQUEST_URL.LOGIN.JUDGE_LOGIN,function(data){
            if(data.returnCode == 0){
                //跳转首页
                window.location.href="index.html";
            }else{
                //没有登录的时候检查cookie
                var username = getCookie("username");
                var loginIdentification = getCookie("loginIdentification");
                if(username != null && loginIdentification != null){
                    postLogin(username, null, null,loginIdentification);
                }
            }
        });

    });
    function userLogin(){
        var username = $("#username").val();
        var password = $("#password").val();
        var verifyCode = $("#verifyCode").val();
        var tipMsg = $("#loginTip");
        if(username != "" && username != null 
        		&& password != "" && password != null 
        		&& verifyCode != "" && verifyCode != null){
        	postLogin(username,password, verifyCode, null);
        }else{
            tipMsg.text("请填写完整再提交登录");
        }
    }
    
    function postLogin(username, password, verifyCode,loginIdentification){
    	var tipMsg = $("#loginTip");
    	$.post(REQUEST_URL.LOGIN.LOGIN,{
            username:username,
            password:password,
            verifyCode:verifyCode,
            loginIdentification:loginIdentification
        },function(data){
            if(data.returnCode==0){
            	if($("#online").is(':checked') == true && loginIdentification == null){
            		setCookie("username", username, 7);
            		setCookie("loginIdentification", data.data.user.loginIdentification, 7);
            	}
                location.href="index.html";
            }else {
                $("#verifyCode").siblings('img').click();
            	tipMsg.text(data.msg);
            }
        });
    }
</script>
</body>
</html>